
"""
剧情分析
"""
from models import Chapter
from pydantic import Field
from core.utils import BaseAnalyzer, prompt_dir


class PlotAnalyzer(BaseAnalyzer):

    def __init__(self):
        super().__init__(prompt_file=prompt_dir / 'context/c1. 情节设计分析.md')

    def invoke(
            self,
            last_chapter: Chapter = Field(description='上一章节的剧情'),
            current_chapter: Chapter = Field(description="当前章节内容")
    ):
        prompt = self.template_prompt.format(
            inputs={
                "plot": last_chapter.plot,
                "chapter_content": current_chapter.chapter_content
            },
            remove_template_variables=True
        )
        current_chapter.plot = self.analyze(prompt)
        return current_chapter.plot
